#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
const int N = 22;
int used[N];
int g[N][N];
string s[N];
int ans;
int n;
void dfs(string temp, int last)
{
	ans = max(ans, (int)temp.size());
	used[last]++;
	for (int i = 0; i < n; i++) {
		if (g[last][i] && used[i] < 2) {
			dfs(temp + s[i].substr(g[last][i]), i);
		}
	}
	used[last]--;
}
int main()
{
	cin >> n;
	char start;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	cin >> start;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			string s1 = s[i];
			string s2 = s[j];
			for (int k = 1; k <= min(s1.size(), s2.size()); k++) {
				if (s1.substr(s1.size() - k, k) == s2.substr(0, k)) {
					g[i][j] = k;
					break;
				}
			}
		}
	}
	for (int i = 0; i < n; i++) {
		if (s[i][0] == start) {
			dfs(s[i], i);
		}
	}
	cout << ans << endl;
	return 0;
}